<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var str2 = '这是老王的身份证号码: 420823200603063216和老周的身份证号码：42086620050321632x和老曾的身份证：422588200106165843';
        var r2 = /[1-9][0-9]{16}[0-9x]/g;
        var res;
        while (res = r2.exec(str2)) {
            console.log(res);

        }
    </script>
</body>

</html>